# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=emacs-magit
pkgver=3.3.0
pkgrel=0
_pkgreal=magit
pkgdesc="Emacs interface for Git"
url="https://magit.vc/"
arch="noarch"
license="GPL-3.0-or-later"
depends="
	cmd:emacs
	cmd:git
	emacs-dash
	emacs-git-commit
	emacs-magit-section
	emacs-with-editor
	"
makedepends="emacs-nox"
subpackages="
	emacs-git-commit
	emacs-magit-section
	"
source="https://github.com/magit/magit/releases/download/v$pkgver/magit-$pkgver.tar.gz"
builddir="$srcdir/$_pkgreal-$pkgver/lisp"
options="!check" # release tarball lacks tests

prepare() {
	default_prepare

	# experimental package requiring unpackaged "libegit2"
	rm -v magit-libgit.el
}

build() {
	emacs -batch -q -no-site-file -L . \
		-f batch-byte-compile \
		./*.el
}

check() {
	HOME="$srcdir" emacs -batch -q -no-site-file -L . -L ../t \
		-l magit-tests -f ert-run-tests-batch-and-exit
}

package() {
	install -Dvm644 ./*.el ./*.elc \
		-t "$pkgdir"/usr/share/emacs/site-lisp/magit/

	cd "$pkgdir"/usr/share/emacs/site-lisp/magit
	emacs -batch -q -no-site-file \
		-eval "(loaddefs-generate \".\" \"$_pkgreal-loaddefs.el\")"
}

commit() {
	pkgdesc="Major mode for editing Git commit messages"
	depends="cmd:emacs emacs-dash emacs-with-editor"

	amove usr/share/emacs/site-lisp/magit/git-commit.el*
}

section() {
	pkgdesc="Collapsible sections like in Magit"
	depends="cmd:emacs emacs-dash"

	amove usr/share/emacs/site-lisp/magit/magit-section.el*
}

sha512sums="
81259a5e7066af31b99b3935fd48c9a76e5001f2cb0fa16c2390c05a464bce13a770c255a44637ba85e6449beeb5af6cd925bca96a6c578da292376c2ae37d76  magit-3.3.0.tar.gz
"
